import org.junit.Test;
import test.ListNode;

/**
 * 1 给定一个链表,判断是否含有环
 */
public class hasCycle {

    @Test
    public void clibe() {
        ListNode list1 = new ListNode(1,new ListNode(2));
        System.out.println(test1(list1));
    }

    public boolean test1(ListNode head) {
        if (head == null) return false;
        ListNode slowwPtr = head, fastPtr = head;
        while (fastPtr.getNext() != null && fastPtr.getNext().getNext() != null) {
            slowwPtr = slowwPtr.getNext();
            fastPtr = fastPtr.getNext().getNext();
            if (slowwPtr == fastPtr) return true;
        }
        return false;
    }
}
